#pragma once
#include <map>
#include <memory>
#include "XnccType.h"

namespace xncc {
namespace foundation {
    class Channel;
    class Poller
    {
      public:
        Poller()                          = default;
        virtual ~Poller()                 = default;
        Poller(const Poller&)             = delete;
        Poller(const Poller&&)            = delete;
        Poller& operator=(const Poller&)  = delete;
        Poller& operator=(const Poller&&) = delete;

        virtual types::IO_MULTI_MODE::value ioType() = 0;

        virtual void addChannel(const std::shared_ptr<Channel>& chnl);
        virtual void removeChannel(const std::shared_ptr<Channel>& chnl);
        virtual void updateChannel(const std::shared_ptr<Channel>& chnl) = 0;
        virtual void loopOnce(int waitUs)                                = 0;
        void         kickInLoop(types::connection_id_t);

      protected:
        using ChannelMap = std::map<int, std::shared_ptr<Channel>>;  // 使用智能指针，保证安全
        ChannelMap channels_;

      private:
        std::map<types::connection_id_t, int> connIdFds_;
    };
}  // namespace foundation
}  // namespace xncc